import java.awt.Font;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

/**
 * 
 * restore book Gui class
 *
 */
public class RestoreBookG extends JPanel implements ActionListener, ListSelectionListener
{

	private static final long serialVersionUID = 1L;
	public JLabel BookManageTitle = null;
	public JButton logout1 = null;
	public JButton cancel = null;
	public JLabel jResAuthorLabel = null;
	public JButton jRestorButton = null;
	public JLabel jDeletedBLabel = null;
	
	/**
	 * This is the default constructor
	 */
	public RestoreBookG() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	public void initialize() 
	{
		jDeletedBLabel = new JLabel();
		jDeletedBLabel.setBounds(new Rectangle(45, 105, 106, 20));
		jDeletedBLabel.setText("Deteted Books:");
		jResAuthorLabel = new JLabel();
		jResAuthorLabel.setText("Author:");
		jResAuthorLabel.setBounds(new Rectangle(420, 120, 45, 16));
		this.setSize(680, 380);
		this.setLayout(null);
		this.add(getBookManageTitle(), null);
		this.add(getCancel(), null);
		this.add(getLogout1(), null);
		this.add(jResAuthorLabel, null);
		this.add(getJRestorButton(), null);
		this.add(jDeletedBLabel, null);
		this.add(Main.restoreBC.jDeleltedBPane, null);
		this.add(Main.restoreBC.jScrollResAuthor, null);
		
		
	}
	
	public JLabel getBookManageTitle() 
	{
		if (BookManageTitle == null) {
			BookManageTitle = new JLabel("Restore Deleted Book");
			BookManageTitle.setFont(new Font("David",Font.ITALIC,30));
			BookManageTitle.setBounds(new Rectangle(120, 38, 283, 44));
		}
		return BookManageTitle;
	}
	JButton getLogout1() {
		if (logout1 == null) {
			logout1 = new JButton("Logout");
			logout1.setBounds(new Rectangle(500, 15, 80, 30));
			logout1.addActionListener(this);
		}
		return logout1;
	}
	public JButton getCancel() {
		if (cancel == null) {
			cancel = new JButton("Back");
			cancel.setBounds(new Rectangle(500, 50, 80, 30));
			cancel.addActionListener(this);
		}
		return cancel;
	}

	@Override
	public void actionPerformed(ActionEvent ae) 
	{
		if(ae.getSource()== getLogout1())
		{
			
			if(JOptionPane.showConfirmDialog(null, "Are you sure you want to logout ?","Confirmation", 0) == 0)
			{
				this.setEnabled(false);
				this.setVisible(false);
				Main.log.loginData[0]=Main.myIP;
				Main.log.loginData[1]="logout";
				Main.log.connection= new ClientQuery(Main.serverIP,5555);
				Main.log.connection.accept("logout");
				Main.log.user.setText("");
				Main.log.pass.setText("");
				Main.log.frame.setSize(650,550);
				Main.log.panel.setEnabled(true);
				Main.log.panel.setVisible(true);
			}
		}
		if(ae.getSource() == getCancel())
		{
			Main.restoreBG.setEnabled(false);
			Main.restoreBG.setVisible(false);
			Main.log.frame.setSize(530, 250);
			Main.bookManagement.panel.setEnabled(true);
			Main.bookManagement.panel.setVisible(true);
			
		}
		if(ae.getSource() == getJRestorButton() )
		{

			if (Main.restoreBC.jDeletedBList.getSelectedValue() == null)
			{
						JOptionPane.showMessageDialog(null,"Please choose a book ","ERROR",JOptionPane.ERROR_MESSAGE);
						return;
			}
			else
				Main.restoreBC.resbook();
		}
		
	}


	@Override
	public void valueChanged(ListSelectionEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	/**
	 * This method initializes jRestorButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	public JButton getJRestorButton() {
		if (jRestorButton == null) {
			jRestorButton = new JButton();
			jRestorButton.setBounds(new Rectangle(490, 290, 140, 40));
			jRestorButton.setText("Restore Book");
			jRestorButton.addActionListener(this);
		}
		return jRestorButton;
	}
}  //  @jve:decl-index=0:visual-constraint="-4,6"
